using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class DrawWeaponContent : MonoBehaviour
{
    public PaintBoard m_PaintBoard;
    public InputField m_NameEdit;
    public Text m_TypeL;
    Weapon m_Weapon;


    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {

    }
    public void Load(Weapon weapon)
    {
        m_Weapon = weapon;
        m_PaintBoard.imageSize = new Vector2Int(64,128);
        var sprite = ResourcesManager.Instance.GetWeaponSprite(weapon.typeID);
        bool isNew = false;
        if (sprite == null)
        {
            sprite = Sprite.Create(new Texture2D(64, 128), new Rect(0, 0, 64, 128), new Vector2(0.5f, 0.5f));
            isNew = true;
        }
        m_PaintBoard.SetSprite(sprite);
        if (isNew)
            m_PaintBoard.ClearUp();

        m_NameEdit.text = m_Weapon.name;
        m_TypeL.text = m_Weapon.m_Type.ToString();
    }
    public void Init()
    {
        m_NameEdit.text = m_Weapon.name;

    }
    public Sprite ApplyData()
    {
        ResourcesManager.Instance.SetWeaponSprite(m_Weapon.typeID, m_PaintBoard.image.sprite);
        return m_PaintBoard.image.sprite;
    }

    public void OnNameEditfinished(string value)
    {
        m_Weapon.name = value;
    }
}
